package com.it2297.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;

import com.it2297.main.App;

public class Order_Full_View {

	private int OrderId;
	private Timestamp DATEORDER;
	private String nric;
	private int payId;
	private double total;
	private Timestamp payDate;
	private String status;
	public int getOrderId() {
		return OrderId;
	}
	public void setOrderId(int orderId) {
		OrderId = orderId;
	}
	public Timestamp getDATEORDER() {
		return DATEORDER;
	}
	public void setDATEORDER(Timestamp dATEORDER) {
		DATEORDER = dATEORDER;
	}
	public String getNric() {
		return nric;
	}
	public void setNric(String nric) {
		this.nric = nric;
	}
	public int getPayId() {
		return payId;
	}
	public void setPayId(int payId) {
		this.payId = payId;
	}
	public double getTotal() {
		return total;
	}
	public void setTotal(double total) {
		this.total = total;
	}
	public Timestamp getPayDate() {
		return payDate;
	}
	public void setPayDate(Timestamp payDate) {
		this.payDate = payDate;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	public ArrayList<Order_Full_View> getAllPaid(String nric){
		ArrayList<Order_Full_View> payList = new ArrayList<Order_Full_View>();
		int id =0;
		try {
			App.mySqlConnection.open();
			String sql = "Select * FROM americano.Payment_OrderList_View where fk_customer_nric =? and status = 'paid'ORDER BY order_id";
			PreparedStatement ps = App.mySqlConnection.getConnection().prepareStatement(sql);
			ps.setString(1, nric);
			ResultSet rs = ps.executeQuery();
			
			while(rs.next()){
				Order_Full_View order = new Order_Full_View();
				order.setAttributes(rs);
				payList.add(order);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			App.mySqlConnection.close();
		}
		return payList;
		
	}
	

	
	private void setAttributes(ResultSet rs) {
		try {
				this.setOrderId(rs.getInt("order_id"));
				this.setNric(rs.getString("fk_customer_nric"));
				this.setDATEORDER(rs.getTimestamp("date_order"));
				this.setPayDate(rs.getTimestamp("date_payment"));
				this.setPayId(rs.getInt("fk_payment_id"));
				this.setStatus(rs.getString("status"));
				this.setTotal(rs.getDouble("amount"));
				
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
